home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / editors / AME / Rexx / vfind.ame < prev    next >
Encoding:
Text File  |  1994-02-01  |  3.8 KB  |  183 lines

  1. /* $VER: VFind 37.1 (21.2.93) */ 
  2. /* This program brings up a Search Requester for AME */
  3.  
  4. if show("l", "rexxarplib.library") = 0 then do
  5.    check = addlib('rexxsupport.library', 0, -30, 0)
  6.    check = addlib('rexxarplib.library',  0, -30, 0)
  7. end
  8.  
  9. options results
  10.  
  11. /*
  12. *   The following sequence determines both AME's screen and port name,
  13. *   and also gets the number screen rows and columns.
  14. */
  15.  
  16. ameport = address()
  17. cols = ScreenCols(ameport)
  18. if cols == -1 then do
  19.    amescreen = ""
  20.    cols = ScreenCols()
  21.    rows = ScreenRows()
  22. end
  23. else do
  24.    amescreen = ameport
  25.    rows = ScreenRows(amescreen)
  26. end
  27. /*
  28.  *   Set up a host. This time, send all messages to our own port.
  29.  */
  30.  
  31. address AREXX "'x = CreateHost(AMESEARCH, MFLAGSPORT, "amescreen")'"
  32. /*
  33.  *   Wait until it is ready.
  34.  */
  35. do i = 1
  36.    if showlist('p', AMESEARCH) ~= 0 then leave
  37.    call delay 30
  38. end
  39.  
  40. /*
  41.  *   Open the window
  42.  */
  43.  
  44. idcmp = 'CLOSEWINDOW+GADGETUP'
  45. flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
  46.  
  47. call OpenWindow(AMESEARCH, (cols - 640)/2, rows - 190, 600, 120, idcmp,   ,
  48.                 flags, "Find...")
  49.  
  50. /*
  51.  *   Open the port that messages will come to
  52.  */
  53. mp = openport(MFLAGSPORT)
  54.  
  55.  
  56. /*
  57.  *   Read the current search settings
  58.  */
  59. 'getlastpattern'
  60. findstring = result
  61. "getprefs" "case"
  62. caseflag = result
  63. "getprefs" "regex"
  64. regexflag = result
  65.  
  66. direct = 1
  67.  
  68. /*
  69.  *   Add the gadgets
  70.  */
  71.  
  72. call AddGadget(AMESEARCH, 50,   28, 2, findstring, "%d%1%g", 160, RIDGEBORDER)
  73. call AddGadget(AMESEARCH, 360,  28, 0, "  ", "%d")
  74. call AddGadget(AMESEARCH, 360,  46, 1, "  ", "%d")
  75. call AddGadget(AMESEARCH, 360,  64, 3, "  ", "%d")
  76. call AddGadget(AMESEARCH, 110,  46, 4, "Again", "%d")
  77.  
  78. Call Move(AMESEARCH,220,34)
  79. Call Text(AMESEARCH,"Search String")
  80. Call Move(AMESEARCH,400,34)
  81. call Text(AMESEARCH, "Case Sensitive")
  82. Call Move(AMESEARCH,400,52)
  83. call Text(AMESEARCH, "Regular Expression")
  84. Call Move(AMESEARCH,400,68)
  85. call Text(AMESEARCH, "Forward Search")
  86.  
  87. call AddGadget(AMESEARCH, 50, 84, "USE",   "\    OK    \  ", "USE")
  88. call AddGadget(AMESEARCH,450, 84, "CLOSE", "\   Cancel  \  ", "CANCEL")
  89.  
  90.  
  91. /* set things up for the cancel */
  92.  
  93. uncase = 'unsetprefs'
  94. unregex = 'unsetprefs'
  95.  
  96. /*
  97.  *   set gadgets that should be on
  98.  */
  99.  
  100.  
  101. if compare(caseflag,"CASE") = 0 then do
  102.     res = SetGadget(AMESEARCH, 0, "ON")
  103.     uncase = 'setprefs'
  104.     end
  105.  
  106. if compare(regexflag,"REGEX") = 0 then do
  107.     res = SetGadget(AMESEARCH, 1, "ON")
  108.     unregex = 'setprefs'
  109.     end
  110.  
  111. res = SetGadget(AMESEARCH, 3, "ON" )
  112.  
  113. /*
  114.  *   Main event loop
  115.  */
  116. quitflag  = 0
  117.  
  118. do forever
  119.    if quitflag = 1 then leave
  120.    t = waitpkt(MFLAGSPORT)
  121.    do forever
  122.       p = getpkt(MFLAGSPORT)
  123.       if c2d(p) = 0 then leave
  124.       cmd = getarg(p)
  125.       if cmd = 2 then findstring = getarg(p,1)
  126.       t = reply(p, 0)
  127. /*
  128.  *   See what we got
  129.  */
  130.       if cmd = "CANCEL" then do
  131.          call CloseWindow(AMESEARCH)
  132.      /* cancel changes in find preferences */
  133.      uncase "CASE"
  134.      unregex "REGEX"
  135.          quitflag = 1
  136.       end
  137.       else if cmd = "USE" | cmd = "CLOSEWINDOW" then do
  138.          call CloseWindow(AMESEARCH)
  139.          quitflag = 1
  140.       end
  141.       else if cmd = "2" | cmd = 4 then do
  142.     if direct = 1 then 'find' findstring
  143.     else 'findprev' findstring
  144.     if rc ~= 0 then 'beepscreen'
  145.       end
  146.       else if cmd = "0" then do
  147.     if compare(caseflag,"CASE") = 0 then do
  148.         call SetGadget(AMESEARCH, cmd, "OFF")
  149.         'unsetprefs' "CASE"
  150.     end
  151.     else do
  152.         call SetGadget(AMESEARCH, cmd, "ON")
  153.         'setprefs' "CASE"
  154.     end
  155.         'getprefs' "CASE"
  156.         caseflag = result
  157.       end
  158.       else if cmd = "1" then do
  159.     if compare(regexflag,"REGEX") = 0 then do
  160.         call SetGadget(AMESEARCH, cmd, "OFF")
  161.         'unsetprefs' "REGEX"
  162.     end
  163.     else do
  164.         call SetGadget(AMESEARCH, cmd, "ON")
  165.         'setprefs' "REGEX"
  166.     end
  167.         'getprefs' "REGEX"
  168.         regexflag = result
  169.       end
  170.       else if cmd = "3" then do
  171.     if direct = 0 then do
  172.         direct = 1
  173.         call SetGadget(AMESEARCH, cmd, "ON")
  174.     end
  175.     else do
  176.         call SetGadget(AMESEARCH, cmd, "OFF")
  177.            direct = 0
  178.     end
  179.       end
  180.    end
  181. end
  182.  
  183. exit